package com.zzy.service.impl;

import com.zzy.dao.BaseDao;
import com.zzy.model.CompleteParams;
import com.zzy.model.FlowAudit;
import com.zzy.service.FlowAuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**流程走过的节点 审核信息
 *  @Author zzy
 *  @Time 2018年11月21日14:12:26
 */
@Transactional
@Service()
public class FlowAuditServiceImpl implements FlowAuditService {
    @Autowired
    private BaseDao<FlowAudit> basedao;
    public FlowAudit getUnique(String hql, Object[] param) {
        return basedao.get(hql,param );
    }

    public FlowAudit getByID(String id) {
        return basedao.get(FlowAudit.class,id );
    }

    public List<FlowAudit> getList(String hql, Object[] param) {
        return  basedao.find(hql,param );
    }

    public List<FlowAudit> getListByStepId(String stepId) {
        if(StringUtils.hasText(stepId)){
            String hql = " from FlowAudit where stepId=?";
            return  basedao.find(hql,new Object[]{stepId} );
        }
        return null;
    }

    public Integer save(FlowAudit model) {
        int i = 1;
        try {
            basedao.save(model);
        } catch (Exception e) {
            i = -1;
        }
        return i;
    }


    public String save(CompleteParams params){
        FlowAudit model =new FlowAudit();
        model.setStepId(params.getActTaskId());
        model.setAuditUserName(params.getUser());
        model.setFiles(params.getLinkurl());
        save(model);
        if(model.getId()!=null){
            return  model.getId();
        }else{
            return "";
        }
    }

    public Integer del(String id) {
        int i = 1;
        try {
            if (StringUtils.hasText(id)){
                FlowAudit o = new FlowAudit();
                o=this.getByID(id);
                basedao.delete(o);
            }
        } catch (Exception e) {
            i = -1;
        }
        return i;
    }





    public Integer update(FlowAudit model) {
        int i = 1;
        try {
            basedao.update(model);
        } catch (Exception e) {
            i = -1;
        }
        return i;
    }

    public Integer saveOrUpdate(FlowAudit model) {
        int i = 1;
        try {
            basedao.saveOrUpdate(model);
        } catch (Exception e) {
            i = -1;
        }
        return i;
    }


}
